package mytest;

import java.util.stream.IntStream;

public class ThreadLocalTest {

    public static void main(String[] args) {
        test1();
    }


    public static void test1() {

        ThreadLocal<String> local = new ThreadLocal<>();

//        IntStream.range(0, 10).forEach(i -> new Thread(() -> {
//            local.set(Thread.currentThread().getName() + ":" + i);
//            System.out.println("线程：" + Thread.currentThread().getName() + ",local:" + local.get());
//        }).start());

        var string = "zhangsan";

        for (var i = 0; i < 5; i ++) {
             final int number = i;
            new Thread(() -> {
                local.set(Thread.currentThread().getName() + ":" + number);
                System.out.println(Thread.currentThread().getName());
            }).start();
        }
    }
}
